<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>文件列表</title>
    <meta charset="UTF-8">

    <script src="../../../js/jquery-2.0.3.min.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrap.min.css">
    <script src="../../../js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrapValidator.css">
    <script src="../../../js/bootstrapValidator.js"></script>
    <script src="../../../js/jquery.cookie.js"></script>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="../../../js/hostConfig.js"></script>

</head>
<body>
<div class="container kv-main" id="app">
    <div class="jumbotron">
        <h1>后台首页</h1>
        <p></p>
    </div>
    <form name="form" action="" method="post" enctype="multipart/form-data" class="form-horizontal">

        <div class="form-group">
            <label class="col-lg-1 control-label">角色Id</label>
            <div class="col-lg-6">
                <input type="text" id="id" name="name" class="form-control" placeholder="角色名称"
                       v-model="id"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-1 control-label">名称</label>
            <div class="col-lg-6">
                <input type="text" id="name" name="name" class="form-control" placeholder="角色名称"
                       v-model="role.name">
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-1 control-label">描述</label>
            <div class="col-lg-6">
                <input type="text" id="description" name="description" class="form-control" placeholder="角色描述"
                       v-model="role.description">
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-1 control-label">拥有权限</label>

            <div class="col-lg-6">
                <div>
                    <label>
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <th>名称</th>
                                <th>描述</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr v-for="p in todos">
                                <td>
                                    <span v-text="p.name"></span>
                                </td>
                                <td>
                                    <span v-text="p.description"></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </label><br>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-1 control-label"></label>
            <div class="col-lg-4 col-lg-offset-1">
                <input class="btn btn-info btn-block" type="submit">
            </div>
        </div>
    </form>
</div>

</body>
</html>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            id: "",
            name: "",
            mobilephone: "",
            password: "",
            role: {},
            todos: []
        },
        mounted() {
            this.id = this.$options.methods.getUrlParam('id');
            axios({method: 'post', url: host_tomcatR + '/role/queryRoleById?id='+ this.id, withCredentials: true}).then(res => this.role = res.data);
            axios({method: 'post', url: host_tomcatR + '//p/list', withCredentials: true}).then(res => this.todos = res.data);
        },
        methods: {
            submitUserInfo: function () {
                console.log(this.permissions);
                axios({
                    method: 'post',
                    url: '/auth/role/add',
                    data: {
                        name: this.name,
                        description: this.description,
                        permissions: this.permissions
                    }
                }).then(function (response) {
                    if (response.data.code != "0000") {
                        alert(response.data.description);
                        console.log(response.data);
                    } else {
                        window.location.href = "/pages/manage/user/list.html";
                    }
                });
            },

            getUrlParam: function (key) {
                var reg = new RegExp(key + '=([^&]*)');
                var results = location.href.match(reg);
                return results ? results[1] : null;
            }
        }
    });
</script>